<?php

require('./php_aiplat/include.php');
require_once './common.php';

//请在此填入AppID与AppKey
$app_id = '2132956759';
$app_key = 'RlkKqKYGDlngTS12';

//设置AppID与AppKey
Configer::setAppInfo($app_id, $app_key);

$headers= getallheaders();

// var_dump($headers);
// var_dump($_SERVER);

must_post_request();

// application/x-www-form-urlencoded
// multipart/form-data

$content_type = $headers['Content-Type'];

if($content_type == 'application/x-www-form-urlencoded'){
    $image=$_POST['image'];
    // echo $image  . PHP_EOL;
    // $image_data = file_get_contents('./php_aiplat/data/generalocr.jpg');
    // $params = array(
    // 'image' => base64_encode($image_data),
    // );
    // echo base64_encode($image_data);
    $params = array( 'image' => $image );
    $response = API::generalocr($params);
    // var_dump($response);
    echo $response;
    exit;
}

if(strpos($content_type, 'multipart/form-data') >=0){
    if(!empty($_FILES['image'])){
        $image_data = file_get_contents($_FILES['image']['tmp_name']);
        $params = array( 'image'=> base64_encode($image_data) );
        $response = API::generalocr($params);
        echo $response;
        exit;
    }else{
        echo json_encode(['ret'=>1101, 'msg'=>'form-data need [image] file']);
    }
}


